<template>
    <div>
        <input v-model="text" placeholder="输入文本生成二维码地址" />
        <button @click="generateQRCodeURL">生成二维码地址</button>
        <button v-if="qrCodeURL" @click="downloadTXT">下载文本文件</button>
        <div v-if="qrCodeURL">
            <p>二维码地址：<a :href="qrCodeURL" target="_blank">点击查看二维码</a></p>
        </div>
    </div>
</template>
<script setup lang="ts">
import { ref, inject, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRouter, useRoute } from 'vue-router'
import { type AxiosStatic } from 'axios'
const dialogVisible = ref(false)
import QRCode from 'qrcode';

const axios = inject('axios') as AxiosStatic
const router = useRouter()
const route = useRoute()
//生成二维码
const text = ref('');
const qrCodeURL = ref('');
const generateQRCodeURL = () => {
    QRCode.toDataURL(text.value)
        .then((url: any) => {
            qrCodeURL.value = url;
        })
        .catch((err: any) => {
            console.error(err);
        });
};
// 导出文本文件
const downloadTXT = () => {
    const blob = new Blob([qrCodeURL.value], { type: 'text/plain;charset=utf-8' });
    const link = document.createElement('a');
    link.href = URL.createObjectURL(blob);
    link.download = 'qrcode-url.txt'; // 你可以修改文件名
    link.click();
};

</script>